<script setup>
import { useRouter } from 'vue-router';
import { defineAsyncComponent, onMounted, ref } from 'vue';
import MultipleSelect from '../../components/MultipleSelect.vue';
import Avatar from '../../components/Avatar.vue';

// Select Teacher
const teachers = [{ name: '里哈', id: 1 }, { name: '发文', id: 2 }, { name: '共同', id: 3 }, { name: '那样', id: 4 }, { name: '强大', id: 5 }]
const selected_items = ref([])
function handleSelected(newValue) {
    // console.log(newValue);
    selected_items.value = newValue;
}

// add Student
const team_students_container_ref = ref(null)
const add_img_top = ref(123)
onMounted(() => {
    team_students_container_ref.value.addEventListener('scroll', (e) => {
        // 123是容器顶部到图片底部的距离
        add_img_top.value = e.target.scrollTop + 123
    })
})

// Modal
const RecruitMembers = defineAsyncComponent(() => import('../../components/RecruitMembers.vue'))

const isOpenModal = ref(false)
const modalName = ref('')
function openModal(name) {
    isOpenModal.value = true;
    modalName.value = name
}
function closeModal() {
    isOpenModal.value = false
}

</script>
<template>
    <div class="create-team-container">
        <div class="create-team">
            <p>{{ $t('create_team.title') }}</p>
            <form class="inputs-container">

                <div class="input-container">

                    <label for="team_name">{{ $t('create_team.teamName') }}</label><input type="text" id="team_name" />
                </div>
                <div class="input-container">
                    <label for="team_teacher">{{ $t('create_team.teamTeacher') }}</label>
                    <!--<input type="text" id="team_teacher" /> -->
                    <MultipleSelect class="select-teachers" :items="teachers" :text-field="'name'" :value-field="'id'"
                        @update:selected="handleSelected" />

                </div>
                <div class="input-container">
                    <label for="team_introduction">{{ $t('create_team.teamIntroduction') }}</label><input type="text"
                        id="team_introduction" />

                </div>
                <div class="input-container">
                    <label for="team_leader">{{ $t('create_team.teamLeader') }}</label><input type="text"
                        id="team_leader" />

                </div>
                <div class="input-container">
                    <label for="team_students" style="align-self: start;">{{ $t('create_team.teamStudents') }}</label>
                    <div class="team-students-container" ref="team_students_container_ref">
                        <Avatar v-for="(name, index) in 10" :name="name" :key="index"
                            :url="'/src/assets/images/student/avatar.svg'" :style="{ margin: '5px 15px' }" />
                        <img src="/src/assets/images/student/add.svg" alt="File add"
                            :style="{ top: add_img_top + 'px' }" @click="openModal('recruit_members')" />
                    </div>

                </div>
            </form>
            <div class="button-container">

                <button type="button">{{ $t('create_team.createButton') }}</button>
            </div>
        </div>
        <div class="modal" :class="{ open: isOpenModal }">

            <div class="modal-content-container">
                <div class="modal-content">
                    <div class="modal-header">
                        <img src="/src/assets/images/student/close.svg" alt="Delete" @click="closeModal" />
                    </div>
                    <RecruitMembers v-if="isOpenModal && modalName == 'recruit_members'" />
                </div>
            </div>
        </div>
    </div>


</template>

<style scoped>
.create-team-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.create-team-container>.create-team {
    background-color: #ffffff;
    box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.16);
    width: 1057px;
    height: 662px;
    margin: 50px 0;
    padding: 20px 100px;
}

.create-team-container>.create-team>p {
    width: 100%;
    text-align: center;
    font-family: Source Han Sans CN;
    font-size: 30px;
    font-weight: bold;
    color: #707070;
    margin-bottom: 27px;
}

.create-team-container>.create-team>.inputs-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

.create-team-container>.create-team>.inputs-container>.input-container {
    display: grid;
    justify-content: space-between;
    align-items: center;
    width: 80%;
    grid-template-areas:
        "label input";
    grid-template-columns: 20% 80%;
    margin-bottom: 26px;
}

.create-team-container>.create-team>.inputs-container>.input-container>label {
    font-family: Source Han Sans CN;
    font-size: 20px;
    color: #707070;
    grid-area: label;
    width: 100%;
}

.create-team-container>.create-team>.inputs-container>.input-container>label::after {
    content: ': '
}


.create-team-container>.create-team>.inputs-container>.input-container>input[type=text] {
    width: 100%;
    padding: 9px 17px 11px 17px;
    margin: 5px 0 5px 0;
    display: inline-block;
    border: solid 1px #8a8a8a;
    background-color: transparent;
    border-radius: 10px;
    height: 36px;
    font-size: 16px;
    font-family: Source Han Sans CN;
    grid-area: input;
}

.create-team-container>.create-team>.inputs-container>.input-container>input[type=text]:focus {
    background-color: #ddd;
    outline: none;
}

/*  选择指导老师 */
.create-team-container>.create-team>.inputs-container>.input-container>.select-teachers {
    grid-area: input;
}

/* 成员信息 */
.create-team-container>.create-team>.inputs-container>.input-container>.team-students-container {
    display: flex;
    flex-wrap: wrap;
    padding: 9px 17px 11px 17px;
    border: solid 1px #8a8a8a;
    background-color: transparent;
    border-radius: 10px;
    height: 172px;
    font-size: 16px;
    font-family: Source Han Sans CN;
    grid-area: input;
    overflow-y: scroll;
    position: relative;
}

.create-team-container>.create-team>.inputs-container>.input-container>.team-students-container>img {
    position: absolute;
    cursor: pointer;
    right: 0px;
}


.create-team-container > .create-team > .button-container {
    width: 100%;
    text-align: center;
}

.create-team-container > .create-team > .button-container > button {
    width: 326px;
    height: 45px;
    cursor: pointer;
    padding: 0;
    border: none;
    border-radius: 10px;
    background-color: #8493a6;
    color: #F5F5F5;
    line-height: 45px;
    font-size: 18px;
    font-family: Source Han Sans CN;
    letter-spacing: 2px;
    opacity: 0.85;
    margin-top: 16px;
}

.create-team-container > .create-team > .button-container > button:hover {
    opacity: 1;
}

.create-team-container > .create-team > .button-container > button:active {
    transform: translateY(3px);
}

.create-team-container > .modal {
    display: none;
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.5);
    overflow: auto;
    z-index: 15;
}

.create-team-container > .modal.open {
    display: block;
}

.create-team-container > .modal > .modal-content-container {
    display: flex;
    width: 100%;
    /* height: 100%;*/
    justify-content: center;
    align-items: center;
}


.create-team-container > .modal > .modal-content-container > .modal-content {
    width: 837px; 
	/*height: 491px;*/
    background-color: #ffffff;
    border: none;
	box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.16);
    padding: 20px 54px;
    margin: 50px 0;
}

.create-team-container >  .modal > .modal-content-container >.modal-content > .modal-header {
    display: flex;
    justify-content: end;
    align-items: center;
}

.create-team-container > .modal > .modal-content-container > .modal-content > .modal-header > img{
    cursor: pointer;
    user-select: none;
    transition: transform 0.25s;
}

.create-team-container > .modal > .modal-content-container > .modal-content > .modal-header > img:hover {
    transform: rotate(90deg);
}
</style>